package com.atguigu.lease.common.bloomFilter;

import java.util.BitSet;

/*
*功能：
 作者：chenhao
*日期： 2025/3/20 下午5:17
*/
public class BloomFilterConfig {



    private BitSet bits;
    private int size;
    private HashStrategy strategy;

    public BloomFilterConfig(int size, HashStrategy strategy) {
        this.size = size;
        this.bits = new BitSet(size);
        this.strategy = strategy;
    }

    public void add(String value) {
        for (int i = 0; i < 3; i++) {
            int hash = strategy.hash(value, i) % size;
            bits.set(hash);
        }
    }

    public boolean mightContain(String value) {
        for (int i = 0; i < 3; i++) {
            int hash = strategy.hash(value, i) % size;
            if (!bits.get(hash)) return false;
        }
        return true;
    }

}
